import java.io.FileOutputStream;

/**
 * Created by IntelliJ IDEA.
 * User: roll
 * Date: 9/9/11
 * Time: 4:21 PM
 * To change this template use File | Settings | File Templates.
 */
public class mapper {

    public static boolean class_implements = false;
    public static boolean class_Debug = false;
    public static String class_SBefore = "N";
    public static String class_SAfter = "N";
    public static int class_oD_pos = 0;
    private byte byteArray[];
    public static byte[] class_outData;
    public static String class_CodeLine = "";
    public static boolean class_EndOfCode = false;

    public static boolean class_Declare = false;
    public static boolean class_Class = false;
    public static boolean class_inClass = false;
    public static boolean class_ClassExtends = false;
    public static String class_Indent = "";  /* +: Add one level, -: Remove one level, 0: Reset to zero */
    public static int class_Indent_size = 0;

    public static int INDENT_SIZE = 3;

    public static String SQL_LITERAL = "SQL";
    public static String XSLT_LITERAL = "XSLT";
    public static String CALL_LITERAL = "Call Section";
    public static String PC_LITERAL = "PeopleCode";
    public static String LOGMSG_LITERAL = "Log Message";
    public static String EXIT_LITERAL = "EXIT";
    public static String WRITE_LITERAL = "WRITE";
    public static String RETURN_LITERAL = "RETURN";

    public static boolean class_Output_To_File = false;
    public static boolean class_Output_To_Screen = true;
    public static boolean class_Output_AESQL = true;
    public static boolean class_Output_AEPC = true;
    public static boolean class_Evaluate = false;

    public static FileOutputStream class_outFile;

    static String getComment() {

        String currentMethod = "getComment:";

        int comment_length = 0;

        class_oD_pos++; /* Next byte, the comment length has 2 bytes low order first */

        /* The length byte is bit wide ANDed and cast to integer. */
        comment_length = (int) class_outData[class_oD_pos] & 0xff;

        class_oD_pos++; /* Next byte */

        comment_length = comment_length + ((int) class_outData[class_oD_pos] & 0xff) * 256;

        if (class_Debug) System.out.println(currentMethod + "comment_length= " + comment_length);

        String $out_String = "";
        char tmp_c;

        for (int i = 1; i <= comment_length; i++) {

            if (class_outData[class_oD_pos] != 0) {
                tmp_c = (char) class_outData[class_oD_pos];
                $out_String = $out_String + tmp_c;
            }
            class_oD_pos++; /* Next byte */
        }

        if (class_Debug) System.out.println(currentMethod + "$out_String=" + $out_String);

        return $out_String;
    }

    public mapper() {

    }

    static String getNumber(int gN_bytes) {

        String currentMethod = "getNumber:";

        /* Handles whatever is stored, but displays large and pricise numbers using
   scientific notation. Example bugabo: 312345678901234567890123456789012 */

        double nValue = 0.0;
        int dValue = 0;   /* decimal position from far right going left */
        String out_number = "";
        boolean display_integer = true;
        int num_bytes = gN_bytes - 3;

        class_oD_pos++;  /* Skip the first byte */

        class_oD_pos++;  /* Decimal position is in the second byte. */
        dValue = (int) class_outData[class_oD_pos];

        class_oD_pos++;  /* Move to the 3rd byte */

        /* Base 256 number without decimal starts at 3rd byte and goes for 16 bytes. */
        for (int i = 0; i < num_bytes; i++) {
            /* AND the byte with xFF so casting to integer does an unsigned conversion. */
            nValue = nValue + ((int) (class_outData[class_oD_pos] & 0xff) * Math.pow(256, i));
            if ((i > 2) && (!((int) (class_outData[class_oD_pos] & 0xff) == 0)))
                display_integer = false;
            class_oD_pos++;
        }

        if ((dValue == 0) && (display_integer))
            /* No decimal and it's relatively small, cast to integer. */
            out_number = String.valueOf((int) nValue);
        else {
            /* If there is a deciaml value, use it to set the decimal position. */
            out_number = String.valueOf((double) nValue * Math.pow(10, (-1 * dValue)));
        }
        return out_number;
    }

    static String get_String() {

        String currentMethod = "get_String:";

        /* PeopleCode string characters are stored as two byte characters. With the
           standard ASCII, only the first byte is used. I have not bothered trying to
           support this yet since we are using just ASCII. I am reading the first byte,
           and then just junking the second byte (reading, but doing nothing).
        */
        /* Spins through bytes until the ASCII position is zero, i.e., end of string. */

        String $out_String = "";
        char tmp_c;

        /* Move to the next byte */
        class_oD_pos++;

        while (class_outData[class_oD_pos] != 0) {

            tmp_c = (char) class_outData[class_oD_pos]; /* Cast byte array member to a char. */
            $out_String = $out_String + tmp_c;

            class_oD_pos++; /* Junk 00 byte */
            class_oD_pos++; /* Possible ASCII char */

        }
        class_oD_pos++;  /* Position to next byte */

        return $out_String;
    }

    static String lineFeed(String lF_Disposition) {

        String currentMethod = "lineFeed:";

        String indenter = "";
        String lF_Output = "";
        byte[] out_b;

        /* Indentation preprocessing */
        if (class_Indent.equalsIgnoreCase("-") && (class_Indent_size >= INDENT_SIZE))
            class_Indent_size = class_Indent_size - INDENT_SIZE;

        if (class_Indent.equalsIgnoreCase("B") && (class_Indent_size >= INDENT_SIZE))
            class_Indent_size = class_Indent_size - INDENT_SIZE;

        if (class_Indent.equalsIgnoreCase("R") && (class_Indent_size >= INDENT_SIZE))
            class_Indent_size = class_Indent_size + INDENT_SIZE;

        if (class_Indent.equalsIgnoreCase("0"))
            class_Indent_size = 0;

        /* Do the indentation */
        for (int i = 1; i <= class_Indent_size; i++) {
            indenter = indenter + " ";
        }


        class_CodeLine = indenter + class_CodeLine;

        if (lF_Disposition.equals(RETURN_LITERAL)) {

            /* Output returned by method. */
            /* PeopleCode and SQL are being formatted for output as part of an App Engine. */
            lF_Output = "\t" + class_CodeLine + "\n";

        } else {

            /* Output written to screen or file */

            if (class_Output_To_Screen)
                System.out.println(class_CodeLine);

            if (class_Output_To_File) {

                class_CodeLine = class_CodeLine + "\n";

                out_b = class_CodeLine.getBytes();

                try {
                    class_outFile.write(out_b);
                } catch (Exception e) {
                    System.out.println(currentMethod + " Error is " + e.toString());
                }
            }
        }

        /* Indentation post processing */
        if (class_Indent.equalsIgnoreCase("+"))
            class_Indent_size = class_Indent_size + INDENT_SIZE;

        if (class_Indent.equalsIgnoreCase("B"))
            class_Indent_size = class_Indent_size + INDENT_SIZE;

        if (class_Indent.equalsIgnoreCase("R"))
            class_Indent_size = class_Indent_size - INDENT_SIZE;

        class_CodeLine = "";
        class_Indent = "";

        return lF_Output;
    }

    static String PCdecoder(/*Connection dPC_dbconn, */ int dPC, String dPC_WhereClause, String dPC_disposition) {

        String currentMethod = "PCdecoder:";

        /*
        ! This list is not conclusive. There are still many gaps. I can only assume
        ! that every number has a meaning...but some of these could be for obsolete
        ! commands and so no longer used. Currently it will stop when it encounters an
        ! unrecognized code.
        */

        String $tString = "";
        String dPC_return = "";
        String[] dPC_RecRef;
        int NameNum1 = 0;
        int NameNum2 = 0;

        switch (dPC) {
            case 1:  /* 0x01 */
                class_SBefore = "P";
                $tString = get_String();
                writeCode($tString);
                class_SAfter = "P";
                break;
            case 3:  /* 0x03 */
                class_SBefore = "N";
                writeCode(",");
                class_SAfter = "Y";
                break;
            case 4:  /* 0x04 */
                class_SBefore = "Y";
                writeCode("/");
                class_SAfter = "Y";
                break;
            case 5:  /* 0x05 */
                class_SBefore = "N";
                writeCode(".");
                class_SAfter = "N";
                break;
            case 6:  /* 0x06 */
                class_SBefore = "Y";
                writeCode("=");
                class_SAfter = "Y";
                break;
            case 7:  /* 0x07 */
                /* End of code */
                class_EndOfCode = true;
                break;
            case 8:  /* 0x08 */
                class_SBefore = "Y";
                writeCode(">=");
                class_SAfter = "Y";
                break;
            case 9:  /* 0x09 */
                class_SBefore = "Y";
                writeCode(">");
                class_SAfter = "Y";
                break;
            case 10:  /* 0x0a */
                /* Function | Method | External Datatype | Class name */
                class_SBefore = "P";
                $tString = get_String();
                writeCode($tString);
                class_SAfter = "P";

                /* If in a class definition, look ahead to the next byte to check for "extends" or "implements" */
                if (class_Class) {

                    /* Log: 200709-format  Start */

                    /* if ((int)(class_outData[class_oD_pos + 1] & 0xff) != 92) { */

                    if (((int) (class_outData[class_oD_pos + 1] & 0xff) != 92) &&
                            ((int) (class_outData[class_oD_pos + 1] & 0xff) != 114)) {

                        /* Log: 200709-format  end   */

                        /* If no class extends do a line feed */
                        dPC_return = lineFeed(dPC_disposition);
                    } else {
                        class_ClassExtends = true;
                    }
                    class_Class = false;
                }

                break;
            case 11:  /* 0x0b */
                class_SBefore = "N";
                writeCode("(");
                class_SAfter = "N";
                break;
            case 12:  /* 0x0c */
                class_SBefore = "Y";
                writeCode("<=");
                class_SAfter = "Y";
                break;
            case 13:  /* 0x0d */
                class_SBefore = "Y";
                writeCode("<");
                class_SAfter = "Y";
                break;
            case 14:  /* 0x0e */
                class_SBefore = "Y";
                writeCode("-");
                class_SAfter = "Y";
                break;
            case 15:  /* 0x0f */
                class_SBefore = "Y";
                writeCode("*");
                class_SAfter = "Y";
                break;
            case 16:  /* 0x10 */
                class_SBefore = "Y";
                writeCode("<>");
                class_SAfter = "Y";
                break;
            case 17:  /* 0x11 */
                /* Indicator of a number coming up */
                $tString = getNumber(14);
                writeCode($tString);
                class_SAfter = "P";
                break;
            case 18:  /* 0x12 */
                /* System variable name */
                class_SBefore = "P";
                $tString = get_String();
                writeCode($tString);
                class_SAfter = "P";
                break;
            case 19:  /* 0x13 */
                class_SBefore = "Y";
                writeCode("+");
                class_SAfter = "Y";
                break;
            case 20:  /* 0x14 */
                class_SBefore = "N";
                writeCode(")");
                class_SAfter = "N";
                break;
            case 21:  /* 0x15 */
                class_SBefore = "N";
                writeCode(";");
                dPC_return = lineFeed(dPC_disposition);
                class_SAfter = "N";
                break;
            case 22:  /* 0x16 */
                /* Quoted literal */
                class_SBefore = "P";
                $tString = get_String();
                $tString = "\"" + $tString + "\"";
                writeCode($tString);
                class_SAfter = "P";
                break;
            case 24:  /* 0x18 */
                class_SBefore = "Y";
                writeCode("And");
                dPC_return = lineFeed(dPC_disposition);
                class_SAfter = "Y";
                break;
            case 25:  /* 0x19 */
                class_SBefore = "Y";
                class_Indent = "B";

                /* Log: 200709-format  Start */

                /* writeCode("Else"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("Else;");
                    class_oD_pos++;
                } else {
                    writeCode("Else");
                }

                /* Log: 200709-format  end   */

                dPC_return = lineFeed(dPC_disposition);
                class_SAfter = "Y";
                break;
            case 26:  /* 0x1a */
                class_SBefore = "Y";
                class_Indent = "-";
                writeCode("End-If");

                /* Log: 200709-format  Start   */
                /* class_SAfter  = "Y"; */
                class_SAfter = "N";
                /* Log: 200709-format  end   */

                break;
            case 27:  /* 0x1b */
                class_SBefore = "Y";
                writeCode("Error");
                class_SAfter = "Y";
                break;
            case 28:  /* 0x1c */
                class_SBefore = "Y";
                class_Indent = "+";
                writeCode("If");
                class_SAfter = "Y";
                break;
            case 29:  /* 0x1d */
                class_SBefore = "Y";
                writeCode("Not");
                class_SAfter = "Y";
                break;
            case 30:  /* 0x1e */
                class_SBefore = "Y";
                writeCode("Or");
                dPC_return = lineFeed(dPC_disposition);
                class_SAfter = "Y";
                break;
            case 31:  /* 0x1f */
                class_SBefore = "Y";

                /* Log: 200709-format  Start */

                /* writeCode("Then"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("Then;");
                    class_oD_pos++;
                } else {
                    writeCode("Then");
                }

                /* Log: 200709-format  end   */

                dPC_return = lineFeed(dPC_disposition);
                class_SAfter = "Y";
                break;
            case 32:  /* 0x20 */
                class_SBefore = "Y";
                writeCode("Warning");
                class_SAfter = "Y";
                break;
            case 33:  /* 0x21 */
                /* PeopleSoft object indicator (w/ Object name) */
                class_SBefore = "P";
                /* Move to next byte */
                class_oD_pos++;
                /* Cast the byte array member to integer */
                NameNum1 = (int) class_outData[class_oD_pos];
                /* Move to the next byte. */
                /* This one is skipped. Could be the high order byte of NameNum. */
                class_oD_pos++;

                dPC_RecRef = getObjectReference(dPC_dbconn, NameNum1, dPC_WhereClause);
                writeCode(dPC_RecRef[1] + "." + dPC_RecRef[2]);

                class_SAfter = "P";
                break;
            case 35:  /* 0x23 */
                class_SBefore = "Y";
                writeCode("|");
                class_SAfter = "Y";
                break;
            case 36:  /* 0x24 */
                $tString = getComment();
                writeCode($tString);
                dPC_return = lineFeed(dPC_disposition);
                break;
            case 37:  /* 0x25 */
                class_SBefore = "Y";
                class_Indent = "+";
                writeCode("While");
                class_SAfter = "Y";
                break;
            case 38:  /* 0x26 */
                class_SBefore = "Y";
                class_Indent = "-";

                /* Log: 200709-format  Start */

                /* writeCode("End-While"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("End-While;");
                    class_oD_pos++;
                } else {
                    writeCode("End-While");
                }

                dPC_return = lineFeed(dPC_disposition);

                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                break;
            case 39:  /* 0x27 */
                class_SBefore = "Y";
                class_Indent = "+";
                writeCode("Repeat");
                dPC_return = lineFeed(dPC_disposition);
                class_SAfter = "Y";
                break;
            case 40:  /* 0x28 */
                class_SBefore = "Y";
                class_Indent = "-";
                writeCode("Until");
                class_SAfter = "Y";
                break;
            case 41:  /* 0x29 */
                class_SBefore = "Y";
                class_Indent = "+";
                writeCode("For");
                class_SAfter = "Y";
                break;
            case 42:  /* 0x2a */
                class_SBefore = "Y";
                writeCode("To");
                class_SAfter = "Y";
                break;
            case 43:  /* 0x2b */
                class_SBefore = "Y";
                writeCode("Step");
                class_SAfter = "Y";
                break;
            case 44:  /* 0x2c */
                class_SBefore = "Y";
                class_Indent = "-";

                /* Log: 200709-format  Start */

                /* writeCode("End-For"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("End-For;");
                    class_oD_pos++;
                } else {
                    writeCode("End-For");
                }

                dPC_return = lineFeed(dPC_disposition);

                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                break;
            case 45:  /* 0x2d */
                /* Code Section Seperator */
                //writeCode("<brk>");
                /* writeCode("==================================================================="); */
                dPC_return = lineFeed(dPC_disposition);
                break;
            case 46:  /* 0x2e */
                class_SBefore = "Y";

                /* Log: 200709-format  Start */

                /* writeCode("Break"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("Break;");
                    class_oD_pos++;
                } else {
                    writeCode("Break");
                }

                dPC_return = lineFeed(dPC_disposition);

                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                break;
            case 47:  /* 0x2f */
                class_SBefore = "Y";

                /* Log: 200709-format  Start */

                /* writeCode("True"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("True;");
                    class_oD_pos++;
                } else {
                    writeCode("True");
                }

                dPC_return = lineFeed(dPC_disposition);

                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                break;
            case 48:  /* 0x30 */
                class_SBefore = "Y";

                /* Log: 200709-format  Start */

                /* writeCode("False"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("False;");
                    class_oD_pos++;
                } else {
                    writeCode("False");
                }

                dPC_return = lineFeed(dPC_disposition);

                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                break;
            case 49:  /* 0x31 */
                class_SBefore = "Y";
                writeCode("Declare");
                class_SAfter = "Y";
                /* Do not indent for "Declare Function" */
                class_Declare = true;
                break;
            case 50:  /* 0x32 */
                class_SBefore = "Y";
                /* Do not indent for "Declare Function" */
                if (!class_Declare) class_Indent = "+";
                writeCode("Function");
                class_SAfter = "Y";
                class_Declare = false;
                break;
            case 51:  /* 0x33 */
                class_SBefore = "Y";
                writeCode("Library");
                class_SAfter = "Y";
                break;
            case 53:  /* 0x35 */
                class_SBefore = "Y";
                writeCode("As");
                class_SAfter = "Y";
                break;
            case 54:  /* 0x36 */
                class_SBefore = "Y";
                writeCode("Value");
                class_SAfter = "Y";
                break;
            case 55:  /* 0x37 */
                class_SBefore = "Y";
                class_Indent = "-";
                writeCode("End-Function");
                class_SAfter = "Y";
                break;
            case 56:  /* 0x38 */
                class_SBefore = "Y";
                writeCode("Return");
                class_SAfter = "Y";
                break;
            case 57:  /* 0x39 */
                class_SBefore = "Y";
                writeCode("Returns");
                class_SAfter = "Y";
                break;
            case 58:  /* 0x3a */
                class_SBefore = "Y";
                writeCode("PeopleCode");
                class_SAfter = "Y";
                break;
            case 59:  /* 0x3b */
                class_SBefore = "Y";
                writeCode("Ref");
                class_SAfter = "Y";
                break;
            case 60:  /* 0x3c */
                class_SBefore = "Y";
                class_Indent = "+";
                writeCode("Evaluate");

                /* Log: 200709-format  Start */
                class_Evaluate = true;
                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                break;
            case 61:  /* 0x3d */
                class_SBefore = "Y";

                /* Log: 200709-format  Start */

                /* Check if currently on Evaluate */
                if (class_Evaluate) {
                    dPC_return = lineFeed(dPC_disposition);
                    class_Evaluate = false;
                }

                class_Indent = "B";
                /* Log: 200709-format  end   */

                writeCode("When");
                class_SAfter = "Y";
                break;
            case 62:  /* 0x3e */
                class_SBefore = "Y";

                /* Log: 200709-format  Start */
                class_Indent = "B";
                /* Log: 200709-format  end   */

                writeCode("When-Other");
                class_SAfter = "Y";
                break;
            case 63:  /* 0x3f */
                class_SBefore = "Y";
                class_Indent = "-";

                /* Log: 200709-format  Start */

                /* writeCode("End-Evaluate"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("End-Evaluate;");
                    class_oD_pos++;
                } else {
                    writeCode("End-Evaluate");
                }

                dPC_return = lineFeed(dPC_disposition);

                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                break;
            case 64:  /* 0x40 */
                /* PeopleCode Variable Type Name */
                class_SBefore = "P";
                $tString = get_String();
                writeCode($tString);
                class_SAfter = "P";
                break;
            case 65:  /* 0x41 */
                /* Parmlist */
                break;
            case 66:  /* 0x42 */
                /* End Parmlist | End of Declare Statement */
                break;
            case 67:  /* 0x43 */
                class_SBefore = "Y";
                writeCode("Exit");
                class_SAfter = "Y";
                break;
            case 68:  /* 0x44 */
                class_SBefore = "Y";
                writeCode("Local");
                class_SAfter = "Y";
                break;
            case 69:  /* 0x45 */
                class_SBefore = "Y";
                writeCode("Global");
                class_SAfter = "Y";
                break;
            case 70:  /* 0x46 */
                class_SBefore = "Y";
                writeCode("**");
                class_SAfter = "Y";
                break;
            case 71:  /* 0x47 */
                class_SBefore = "N";
                writeCode("@");
                class_SAfter = "N";
                break;
            case 73:  /* 0x49 */
                class_SBefore = "Y";
                writeCode("set");
                class_SAfter = "Y";
                break;
            case 74:  /* 0x4a */
                /* PeopleSoft object indicator (w/ Object name) */
                class_SBefore = "P";

                /* Move to the next byte */
                class_oD_pos++;
                /* Cast the byte array member to integer. */
                NameNum1 = (int) class_outData[class_oD_pos];

                /* Move to the next byte */
                /* This one is skipped. Could be the high order byte of NameNum. */
                class_oD_pos++;

                dPC_RecRef = getObjectReference(dPC_dbconn, NameNum1, dPC_WhereClause);

                writeCode(dPC_RecRef[1] + "." + dPC_RecRef[2]);

                class_SAfter = "P";
                break;
            case 75:  /* 0x4b */
                class_SBefore = "Y";
                writeCode("Null");
                class_SAfter = "Y";
                break;
            case 76:  /* 0x4c */
                class_SBefore = "Y";
                writeCode("[");
                class_SAfter = "N";
                break;
            case 77:  /* 0x4d */
                class_SBefore = "N";
                writeCode("]");
                class_SAfter = "Y";
                break;
            case 78:  /* 0x4e */
                /* Comments with a line of code. */
                $tString = getComment();
                writeCode($tString);
                dPC_return = lineFeed(dPC_disposition);
                break;
            case 79:  /* 0x4f */
                /* Blank line */
                dPC_return = lineFeed(dPC_disposition);
                break;
            case 80:  /* 0x50 */
                /* Indicator of a number coming up. */
                /* Arguement is number of bytes used to represent number. */
                $tString = getNumber(18);
                writeCode($tString);
                class_SAfter = "P";
                break;
            case 81:  /* 0x51 */
                class_SBefore = "Y";
                writeCode("PanelGroup");
                class_SAfter = "Y";
                break;
            case 84:  /* 0x54 */
                class_SBefore = "Y";
                writeCode("Component");
                class_SAfter = "Y";
                break;
            case 85:  /* 0x55 */
                $tString = getComment();
                writeCode($tString);
                dPC_return = lineFeed(dPC_disposition);
                break;
            case 86:  /* 0x56 */
                class_SBefore = "Y";
                writeCode("Constant");
                class_SAfter = "Y";
                break;
            case 87:  /* 0x57 */
                class_SBefore = "N";
                writeCode(":");
                class_SAfter = "N";
                break;
            case 88:  /* 0x58 */
                class_SBefore = "Y";
                writeCode("import");
                class_SAfter = "Y";
                break;
            case 89:  /* 0x59 */
                class_SBefore = "N";
                writeCode("*");
                class_SAfter = "N";
                break;
            case 90:  /* 0x5a */
                class_SBefore = "Y";
                class_Indent = "+";
                writeCode("class");
                /* New line after the class name */
                class_Class = true;
                /* Flag indicating within class */
                class_inClass = true;
                class_SAfter = "Y";
                break;
            case 91:  /* 0x5b */
                class_SBefore = "Y";
                class_Indent = "-";

                /* Log: 200709-format  Start */

                /* Look back to the previous byte to check for semi colon */
                if ((int) (class_outData[class_oD_pos - 1] & 0xff) != 21) {
                    /* If there wasn't a semi colon, do a linefeed. */
                    dPC_return = lineFeed(dPC_disposition);
                }

                /* writeCode("end-class"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("end-class;");
                    class_oD_pos++;
                } else {
                    writeCode("end-class");
                }

                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                class_inClass = false;
                break;
            case 92:  /* 0x5c */
                class_SBefore = "Y";
                writeCode("extends");
                class_SAfter = "P";
                break;
            case 93:  /* 0x5d */
                class_SBefore = "Y";
                writeCode("out");
                class_SAfter = "P";
                break;
            case 94:  /* 0x5e */
                class_SBefore = "Y";
                writeCode("property");
                class_SAfter = "Y";
                break;
            case 95:  /* 0x5f */
                class_SBefore = "Y";
                writeCode("get");
                class_SAfter = "Y";
                break;
            case 97:  /* 0x61 */
                class_SBefore = "Y";
                /* If within a class definition, backoff indent */
                //if (class_inClass) class_Indent = "-";

                /* Log: 200709-format  Start */

                if (class_inClass) class_Indent = "B";

                /* writeCode("private"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("private;");
                    class_oD_pos++;
                } else {
                    writeCode("private");
                }

                /* Log: 200709-format  end   */

                //if (class_inClass) class_Indent = "+";
                dPC_return = lineFeed(dPC_disposition);
                class_SAfter = "Y";
                break;
            case 98:  /* 0x62 */
                class_SBefore = "Y";
                writeCode("instance");
                class_SAfter = "Y";
                break;
            case 99:  /* 0x63 */

                /* Check if previous was a class extends or implements definition */

                /* Log: 200709-format  Start */

                /* if (class_ClassExtends) { */

                if (class_ClassExtends || class_implements) {

                    /* Log: 200709-format  end   */

                    dPC_return = lineFeed(dPC_disposition);
                    class_Class = false;

                    /* Log: 200709-format  Start */

                    class_ClassExtends = false;
                    class_implements = false;

                    /* Log: 200709-format  end   */

                }

                class_SBefore = "Y";

                /* Do not indent method if in class declaration */
                if (!class_inClass) class_Indent = "+";

                writeCode("method");
                class_SAfter = "Y";
                break;
            case 100:  /* 0x64 */
                class_SBefore = "Y";
                class_Indent = "-";

                /* Log: 200709-format  Start */

                /* writeCode("end-method"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("end-method;");
                    class_oD_pos++;
                } else {
                    writeCode("end-method");
                }

                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                break;
            case 101:  /* 0x65 */
                class_SBefore = "Y";
                writeCode("try");
                dPC_return = lineFeed(dPC_disposition);
                class_SAfter = "Y";
                break;
            case 102:  /* 0x66 */
                class_SBefore = "Y";
                writeCode("catch");
                class_SAfter = "Y";
                break;
            case 103:  /* 0x67 */
                class_SBefore = "Y";
                writeCode("end-try");
                class_SAfter = "Y";
                break;
            case 105:  /* 0x69 */
                class_SBefore = "Y";
                writeCode("create");
                class_SAfter = "Y";
                break;
            case 106:  /* 0x6a */
                class_SBefore = "Y";

                /* Log: 200709-format  Start */

                /* class_SAfter  = "Y"; */
                /* break; */
                /* writeCode("end-get"); */

                /* Look ahead to the next byte to check for semi colon. */
                if ((int) (class_outData[class_oD_pos + 1] & 0xff) == 21) {
                    writeCode("end-get;");
                    class_oD_pos++;
                } else {
                    writeCode("end-get");
                }

                /* Log: 200709-format  end   */

                class_SAfter = "Y";
                break;
            case 107:  /* 0x6b */
                class_SBefore = "Y";
                writeCode("end-set");
                class_SAfter = "Y";
                break;
            case 109:  /* 0x6d */
                class_SBefore = "Y";
                writeCode("/+ ");
                $tString = get_String();
                writeCode($tString);
                writeCode(" +/");
                dPC_return = lineFeed(dPC_disposition);
                class_SAfter = "N";
                break;
            case 110:  /* 0x6e */
                class_SBefore = "Y";
                writeCode("Continue");
                class_SAfter = "Y";
                break;

            /* Log: 200709-format  Start */

            case 114:  /* 0x72 */
                /* Check if currently in a class definition */
                if (class_Class) {
                    class_implements = true;
                    class_Class = false;
                }
                class_SBefore = "Y";
                writeCode("implements");
                class_SAfter = "Y";
                break;

            /* Log: 200709-format  end   */

            default:
                System.out.println("");
                System.out.println("****************");
                System.out.println("CodeLine: " + class_CodeLine);
                System.out.println("Unknown:" + dPC);
                break;
        }
        return dPC_return;
    }

    static void writeCode(String $inChar) {

        String currentMethod = "writeCode:";

        /* Handle spacing of each character, command, variable, etc. within PeopleCode. */

        String LastChar = class_CodeLine.substring(class_CodeLine.length());
        /* Special characters that a "P" will not add a space before or after */
        String skipper = " ().;,[]|:";

        if ($inChar.length() > 0) {

            if (!class_CodeLine.equalsIgnoreCase("")) {
                if ((class_SAfter.equalsIgnoreCase("Y") && (!LastChar.equalsIgnoreCase(" "))) ||
                        (class_SAfter.equalsIgnoreCase("P") && (skipper.indexOf(LastChar) == 0)
                                && (skipper.indexOf($inChar.substring(0, 1)) == 0))) {
                    class_CodeLine = class_CodeLine + " ";
                    LastChar = " ";
                }

                if ((class_SBefore.equalsIgnoreCase("Y") && (!LastChar.equalsIgnoreCase(" "))) ||
                        (class_SBefore.equalsIgnoreCase("P") && (skipper.indexOf(LastChar) == 0))) {
                    class_CodeLine = class_CodeLine + " ";
                }
            }
            class_CodeLine = class_CodeLine + $inChar;

            class_SAfter = "N";
            class_SBefore = "N";

        }
    }

}
